package jfuzzyprincepless.zarchive.negotiation.protocols.propositionnetwork;

import java.util.List;

import jfuzzyprincepless.agents.INegotiatingAgent;
import jfuzzyprincepless.zarchive.algorithm.structure.ifcnstr.IExecuteIfNegotiation;
import jfuzzyprincepless.zarchive.algorithm.structure.ifcnstr.IIfConstruction;
import jfuzzyprincepless.zarchive.algorithm.structure.ifcnstr.INegotiationIfConstruction;
import jfuzzyprincepless.zarchive.negotiation.IAgentsExporter;
import jfuzzyprincepless.negotiation.IExecutionContext;
import jfuzzyprincepless.negotiation.INegotiation;
import jfuzzyprincepless.negotiation.INegotiationContext;
import jfuzzyprincepless.negotiation.impl.BaseNegotiation;

public class ExecuteIfNegotiation
	extends BaseNegotiation
	implements IExecuteIfNegotiation, IAgentsExporter
{
	private INegotiationIfConstruction ifConstruction;

	private INegotiation subnegotiation;

	public ExecuteIfNegotiation(
		INegotiationIfConstruction ifConstruction,
		INegotiation subnegotiation
	) {
		this.subnegotiation = subnegotiation;
		this.ifConstruction = ifConstruction;
	}

	public ExecuteIfNegotiation(
		INegotiationIfConstruction ifConstruction
	) {
		this(
			ifConstruction,
			new DefaultNegotiation__Q(
				ifConstruction,
				ifConstruction
			)
		);
	}

	public ExecuteIfNegotiation() {
		this(
			INegotiationIfConstruction.EMPTY_CONSTRUCTION
		);
	}

	@Override
	public IIfConstruction getIfConstruction() {
		return ifConstruction;
	}

	@Override
	public void negotiate(INegotiationContext context) {
		context.registerService(this);
		subnegotiation.negotiate(context);
	}

	@Override
	public void execute(IExecutionContext context) {
		subnegotiation.execute(context);
	}

	@Override
	public List<INegotiatingAgent> getAgents() {
		return ((IAgentsExporter)subnegotiation).getAgents();
	}
}
